//
//  LGAccountBidingViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/10.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGSettingViewController.h"
#import "NSBundle+STSystemTool.h"
#import "TMLoginViewController.h"
#import "LGChangePwdViewController.h"
@interface LGSettingViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;
@end

@implementation LGSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    [self configDataSouce];
    [self configTableFooter];
    // Do any additional setup after loading the view.
}
- (void)configDataSouce{
    NSString * version = [NSString stringWithFormat:@"v%@",[NSBundle st_applictionVersin]];
    self.dataSouce = @[
                       [[STTableEasyModel alloc] initWithTextString:@"关于我们" imageName:@"设置" detailString:@""],
                       [[STTableEasyModel alloc] initWithTextString:@"密码修改" imageName:@"设置" detailString:@""],
                       [[STTableEasyModel alloc] initWithTextString:@"检查更新" imageName:@"设置" detailString:version]
                       ];
    [self.tableView reloadData];
}
- (void)configTableFooter{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, 0, UIScreenWidth - 60 , 44)
                                                        title:@"退出登录"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:8
                                              backgroundColor:TM_redColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedLogoutButton];
    }];
    confimButton.st_centerY = 50;
    [confimButton st_showTopLine];
    [confimButton st_showBottomLine];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    self.tableView.tableFooterView = footer;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 24;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    if ([model.textString isEqualToString:@"密码修改"]) {
        [self.navigationController pushViewController:[LGChangePwdViewController new] animated:YES];
    }
    if ([model.textString isEqualToString:@"关于我们"]) {
      
    }
    if ([model.textString isEqualToString:@"检查更新"]) {
        [TMUtils debugSimulationNetWorkWithHadle:^(NSInteger afterTime) {
            [SVProgressHUD showInfoWithStatus:@"已经是最新版本"];
        }];
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelectedLogoutButton{
    [self showAlertCancelAndConfirm:@"确定要退出登录吗?" andWithBlock:^(NSString *name) {
        if ([name isEqualToString:@"确认"]) {
            [[STUserManger defult] removeUserPreferce];
            STNavigationController * nav = [[STNavigationController alloc] initWithRootViewController:[TMLoginViewController new]];
            [UIApplication sharedApplication].keyWindow.rootViewController = nav;
            [[UIApplication sharedApplication].keyWindow st_showAnimationWithType:STAnimationTypesuckEffect];
        }
    }];
    
}
@end

